package com.shambles.manage2.tkmapper.mapper;

import com.shambles.manage2.tkmapper.entity.Cost;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.additional.insert.InsertListMapper;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;

public interface CostMapper extends Mapper<Cost>, InsertListMapper<Cost> {
    /**
     * 费用填写接口
     *
     */
    @Insert("")
    Cost insertCost(Cost cost);

    /**
     * 费用查询接口
     */
    @Select("select * from cost order by time desc")
    List<Cost> querCostAll();


    List<Cost> findAll(String name);

    @Select("SELECT c.guid,c.type name,IFNULL(costCount.number,0) number,IFNULL(costCount.quarantine,0) quarantine,IFNULL(costCount.money,0) money FROM cattle c LEFT JOIN  (SELECT cd.cattle_guid,cd.type,sum(cd.number) number,sum(cd.quarantine_number) quarantine ,sum(cd.money) money FROM cost c INNER JOIN  cost_detail cd ON c.time >${startTime} and c.time< ${endTime} AND c.guid = cd.total_guid GROUP BY cd.cattle_guid) costCount ON c.guid = costCount.cattle_guid")
    List<Map<String, Object>> count(@Param("startTime") Long startTime,@Param("endTime") Long endTime);
}